import pygame
import math

class Arrow (pygame.sprite.Sprite):

    angle,x,y = 0,0,0
    
    def __init__(self,image,userPos):
        pygame.sprite.Sprite.__init__(self)
        self.image = image
        self.rect = self.image.get_clip()

        mosPos = pygame.mouse.get_pos()
        self.angle = math.atan2(mosPos[1]-(userPos[1]+32),mosPos[0]-(userPos[0]+26))
        self.x = userPos[0]+32
        self.y = userPos[1]+32

       
    def update(self,args):
        width,height = args[0],args[1]
        window = pygame.display.get_surface()
        velx = math.cos(self.angle)*10
        vely = math.sin(self.angle)*10
        
        self.x += velx
        self.y += vely
        self.rect.top = self.x 
        self.rect.left = self.y 

        if self.x < 0 or self.x > width or self.y < 0 or self.y > height:
            self.kill()
        arrow1 = pygame.transform.rotate(self.image, 360-self.angle*57.29)
        window.blit(arrow1, (self.x, self.y))
            
    
